package com.example.mypotiota_si.Adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mypotiota_si.Datas.Bangzhu;
import com.example.mypotiota_si.R;

import java.util.ArrayList;

import cn.bmob.v3.util.V;

public class ListViewAdapter_bz extends RecyclerView.Adapter<ListViewAdapter_bz.ViewHolder> {
    public ArrayList<Bangzhu> bangzhu;

    public ListViewAdapter_bz(ArrayList<Bangzhu> bangzhu) {
        this.bangzhu = bangzhu;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= View.inflate(parent.getContext(), R.layout.item_bz_list_view,null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.setData(bangzhu.get(position));
    }

    @Override
    public int getItemCount() {
        if (bangzhu!=null){
            return bangzhu.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView icon;
        private TextView nr;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            icon=itemView.findViewById(R.id.bz_icon_tx);
            nr=itemView.findViewById(R.id.bz_nr);
        }

        public void setData(Bangzhu bangzhu) {
            icon.setImageResource(bangzhu.bz_icon);
            nr.setText(bangzhu.bz_nr);
        }
    }
}
